﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Guline.SupportCMS.Models.Object;
using Guline.SupportCMS.Models.Context;
namespace Guline.SupportCMS.Controllers
{
    public class ComponentController : GulineBaseController
    {
    
        public ActionResult MainMenu()
        {
            int MainMenuID = 1;
            var menus = db.MenuItems.Where(m => m.MenuID == MainMenuID && m.Enable && m.ParentID == null).OrderBy(m => m.Order).Include(m => m.Childrens).Include(m => m.ColorStyle);
            return PartialView(menus);
        }
        public ActionResult HotSlideShowNews(int CategoryID)
        {
            //int ItemTypeStyle = 1;//default 1 display style
            var news = db.Articles.Where(m => m.ArticleCategorys.Where(n => n.CategoryID == CategoryID).FirstOrDefault() != null && m.Enable).Include(m => m.ArticleCategorys).OrderByDescending(m => m.created_Date).Take(7).ToList();
            return PartialView(news);
        }

        public ActionResult HotSlideShowNewsStyle2(int CategoryID)
        {
            //int ItemTypeStyle = 1;//default 1 display style
            var news = db.Articles.Where(m => m.ArticleCategorys.Where(n => n.CategoryID == CategoryID).FirstOrDefault() != null && m.Enable).Include(m => m.ArticleCategorys).OrderByDescending(m => m.created_Date).Take(5).ToList();
            return PartialView(news);
        }
        public ActionResult VideoAndImage()
        {

            return PartialView();
        }
        public ActionResult NewsWithCategory()
        {
            List<Models.ViewModel.CategoryWithArticle> ListCategoryWithArticle = new List<Models.ViewModel.CategoryWithArticle>();
            var category = db.Categories.Where(m => m.Enable && m.ParentID == null).OrderBy(m => m.Order).ToList();
            foreach (var cat in category)
            {
                Models.ViewModel.CategoryWithArticle item = new Models.ViewModel.CategoryWithArticle();
                item.Cat = cat;
                item.List = db.Articles.Where(m => m.ArticleCategorys.Where(n => n.CategoryID == cat.ID).FirstOrDefault() != null && m.Enable).OrderByDescending(m => m.created_Date).Take(5).ToList();
                ListCategoryWithArticle.Add(item);
            }
            return PartialView(ListCategoryWithArticle);
        }
        public ActionResult NewsWithCategorySingle(int CategoryID)
        {

            var category = db.Categories.Where(m => m.Enable && m.ID == CategoryID).OrderBy(m => m.Order).FirstOrDefault();
         
            Models.ViewModel.CategoryWithArticle item = new Models.ViewModel.CategoryWithArticle();
            item.Cat = category;
            item.List = db.Articles.Where(m => m.ArticleCategorys.Where(n => n.CategoryID == category.ID).FirstOrDefault() != null && m.Enable).OrderByDescending(m => m.created_Date).Take(5).ToList();
            return PartialView(item);
        }

        public ActionResult HotVideo(int? CategoryID)
        {

            var videos = db.Videos.Where(m => m.VideoCategorys.Where(n => n.CategoryID == CategoryID).FirstOrDefault() != null && m.Enable).Include(m => m.VideoCategorys).OrderByDescending(m => m.created_Date).Take(5).ToList();
            return PartialView(videos);
        }
        public ActionResult NewsList(int CategoryID)
        {
            var news = db.Articles.Where(m => m.ArticleCategorys.Where(n => n.CategoryID == CategoryID).FirstOrDefault() != null && m.Enable).Include(m => m.ArticleCategorys).OrderByDescending(m => m.created_Date).Take(7).ToList();
            return PartialView(news);
        }

        public ActionResult LastedNews()
        {
            var news = db.Articles.Where(m => m.Enable).OrderByDescending(m => m.ID).Take(4);
            return PartialView(news);
        }
        public ActionResult ReadMore()
        {
            var news = db.Articles.Where(m => m.Enable).OrderByDescending(m => m.ReadCount).Take(4);
            return PartialView(news);
        }
    }
}
